package com.wuye.basic.controller;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.basic.domain.WyHometype;
import com.wuye.basic.service.IWyHometypeService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

import static com.wuye.common.core.domain.AjaxResult.DATA_TAG;

/**
 * 房间类型Controller
 * 
 * @author 小停再出发
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/basic/hometype")
public class WyHometypeController extends BaseController
{
    @Autowired
    private IWyHometypeService wyHometypeService;

    /**
     * 查询房间类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:hometype:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyHometype wyHometype)
    {
        startPage();
//        List<WyHometype> list = wyHometypeService.selectWyHometypeList(wyHometype);
        List<WyHometype> list = wyHometypeService.listByHomeType(wyHometype);
        return getDataTable(list);
    }

    /**
     * 导出房间类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:hometype:export')")
    @Log(title = "房间类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyHometype wyHometype)
    {
        List<WyHometype> list = wyHometypeService.selectWyHometypeList(wyHometype);
        ExcelUtil<WyHometype> util = new ExcelUtil<WyHometype>(WyHometype.class);
        util.exportExcel(response, list, "房间类型数据");
    }

    /**
     * 获取房间类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:hometype:query')")
    @GetMapping(value = "/{homeTypeId}")
    public AjaxResult getInfo(@PathVariable("homeTypeId") Long homeTypeId)
    {
        return success(wyHometypeService.selectWyHometypeByHomeTypeId(homeTypeId));
    }

    /**
     * 新增房间类型
     */
    @PreAuthorize("@ss.hasPermi('basic:hometype:add')")
    @Log(title = "房间类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyHometype wyHometype)
    {
        return toAjax(wyHometypeService.insertWyHometype(wyHometype));
    }

    /**
     * 修改房间类型
     */
    @PreAuthorize("@ss.hasPermi('basic:hometype:edit')")
    @Log(title = "房间类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyHometype wyHometype)
    {
        return toAjax(wyHometypeService.updateWyHometype(wyHometype));
    }

    /**
     * 删除房间类型
     */
    @PreAuthorize("@ss.hasPermi('basic:hometype:remove')")
    @Log(title = "房间类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{homeTypeIds}")
    public AjaxResult remove(@PathVariable Long[] homeTypeIds)
    {
        List<Long> ids = Arrays.stream(homeTypeIds).collect(Collectors.toList());
        boolean b = wyHometypeService.removeBatchByIds(ids);
        return toAjax(b);
    }


    @PreAuthorize("@ss.hasAnyPermi('basic:hometype:remove')")
    @GetMapping("allType")
    public AjaxResult allType(){
        return AjaxResult.success(wyHometypeService.list());
    }
}
